package ext.generic.doc.processors;

import com.ptc.jca.mvc.components.AbstractJcaComponentConfig;
import com.ptc.jca.mvc.components.JcaColumnConfig;
import com.ptc.jca.mvc.components.JcaComponentParams;
import com.ptc.mvc.components.AbstractComponentBuilder;
import com.ptc.mvc.components.ColumnConfig;
import com.ptc.mvc.components.ComponentBuilder;
import com.ptc.mvc.components.ComponentConfig;
import com.ptc.mvc.components.ComponentConfigFactory;
import com.ptc.mvc.components.ComponentParams;
import com.ptc.mvc.components.TableConfig;
import com.ptc.mvc.util.ClientMessageSource;
import com.ptc.netmarkets.model.NmObjectHelper;
import com.ptc.netmarkets.model.NmObjectService;
import com.ptc.netmarkets.util.beans.NmClipboardBean;
import com.ptc.netmarkets.util.beans.NmClipboardUtility;
import com.ptc.netmarkets.util.beans.NmHelperBean;
import java.util.List;
import javax.servlet.ServletRequest;
import org.apache.log4j.Logger;
import wt.log4j.LogR;
import wt.util.WTException;

@ComponentBuilder({"netmarkets.object.clipboard"})
public class ClipboardTableBuilder extends AbstractComponentBuilder
{
  private final ClientMessageSource messageSource = getMessageSource("com.ptc.netmarkets.util.beans.beansResource");
  private static final Logger log = LogR.getLogger(ClipboardTableBuilder.class.getName());

  public List buildComponentData(ComponentConfig paramComponentConfig, ComponentParams paramComponentParams)
    throws WTException
  {
    NmHelperBean localNmHelperBean = ((JcaComponentParams)paramComponentParams).getHelperBean();

    NmClipboardBean localNmClipboardBean = localNmHelperBean.getNmClipboardBean();
    NmClipboardUtility.validateClipboardItems(localNmClipboardBean);

    return NmObjectHelper.service.getInflatedClipboardItems(localNmClipboardBean);
  }

  public ComponentConfig buildComponentConfig(ComponentParams paramComponentParams)
    throws WTException
  {
    NmHelperBean localNmHelperBean = ((JcaComponentParams)paramComponentParams).getHelperBean();
    localNmHelperBean.getRequest().setAttribute("showContextInfo", "false");

    ComponentConfigFactory localComponentConfigFactory = getComponentConfigFactory();
    TableConfig localTableConfig = localComponentConfigFactory.newTableConfig();
    localTableConfig.setId("clipboardList");
    localTableConfig.setType("wt.fc.Persistable");
    localTableConfig.setLabel(this.messageSource.getMessage("3"));
    ((AbstractJcaComponentConfig)localTableConfig).setDescriptorProperty("variableRowHeight", Boolean.valueOf(true));

   // localTableConfig.setActionModel("clipboard_toolbar");
    localTableConfig.setSelectable(true);

    localTableConfig.addComponent(localComponentConfigFactory.newColumnConfig("clipboard_mostRecent", true));
    localTableConfig.addComponent(localComponentConfigFactory.newColumnConfig("clipboard_clippingReason", true));
    localTableConfig.addComponent(localComponentConfigFactory.newColumnConfig("clipboard_type_icon", true));
    localTableConfig.addComponent(localComponentConfigFactory.newColumnConfig("clipboard_number", this.messageSource.getMessage("4"), true));

    localTableConfig.addComponent(localComponentConfigFactory.newColumnConfig("orgid", true));

    ColumnConfig localColumnConfig1 = localComponentConfigFactory.newColumnConfig("version", this.messageSource.getMessage("6"), true);

    localColumnConfig1.setNeed("iterationDisplayIdentifier");
    localTableConfig.addComponent(localColumnConfig1);

    ColumnConfig localColumnConfig2 = localComponentConfigFactory.newColumnConfig("backingVersionOid", false);
    localColumnConfig2.setDataStoreOnly(true);
    localTableConfig.addComponent(localColumnConfig2);

    ColumnConfig localColumnConfig3 = localComponentConfigFactory.newColumnConfig("nmActions", false);
    ((JcaColumnConfig)localColumnConfig3).setDescriptorProperty("actionModel", "clipboard_row_actions");

    localTableConfig.addComponent(localColumnConfig3);

    ColumnConfig localColumnConfig4 = localComponentConfigFactory.newColumnConfig("clipboard_name", this.messageSource.getMessage("8"), true);

    localColumnConfig4.setNeed("name");
    localTableConfig.addComponent(localColumnConfig4);

    if (NmClipboardUtility.isShowThumbnailEnabled()) {
      ColumnConfig localColumnConfig5 = localComponentConfigFactory.newColumnConfig("clipboard_thumbnail", this.messageSource.getMessage("9"), true);
      localColumnConfig5.setNeed("thumbnail");
      localColumnConfig5.setExactWidth(true);
      ((JcaColumnConfig)localColumnConfig5).setDescriptorProperty("justify", "center");
      localTableConfig.addComponent(localColumnConfig5);
    }

    ColumnConfig localColumnConfig5 = localComponentConfigFactory.newColumnConfig("clipboard_description", this.messageSource.getMessage("10"), true);

    localColumnConfig5.setNeed("description");
    localTableConfig.addComponent(localColumnConfig5);

    ColumnConfig localColumnConfig6 = localComponentConfigFactory.newColumnConfig("clipboard_parent", this.messageSource.getMessage("11"), true);

    localColumnConfig6.setNeed("containerName");
    localTableConfig.addComponent(localColumnConfig6);

    localTableConfig.setHelpContext("ClipboardTableRef");
    localTableConfig.setView("/netmarkets/object/clipboard_table.jsp");

    if (log.isDebugEnabled()) {
      log.debug("Configured tableConfig : " + localTableConfig);
    }
    return localTableConfig;
  }
}
